//
//  LSExponentSubNode.m
//  LookScore
//
//  Created by nice on 2018/7/30.
//  Copyright © 2018年 ChongQingXunTiCompany. All rights reserved.
//

#import "LSExponentSubNode.h"
#import "LSAIHistoricaModel.h"
@interface LSExponentSubNode()

@property (nonatomic,strong)UILabel *companyName;
@property (nonatomic, strong) NSMutableArray *instantLableArray;
@property (nonatomic, strong) NSMutableArray *firstCountArray;
@end
@implementation LSExponentSubNode{
    
    ASDisplayNode * _displayNode;
    NSInteger _type;
}
//- (UILabel *)companyName{
//    if (!_companyName) {
//        dispatch_async(dispatch_get_main_queue(), ^{
//
//        });
//
//    }
//    return _companyName;
//}
- (NSMutableArray *)instantLableArray{
    if (!_instantLableArray) {
        _instantLableArray = [NSMutableArray array];
        
    }
    return _instantLableArray;
}
- (NSMutableArray *)firstCountArray{
    if (!_firstCountArray) {
        _firstCountArray = [NSMutableArray array];
        
    }
    return _firstCountArray;
    
}
- (instancetype)initWithType:(NSInteger)type With:(id)model{
    if (self = [super init]) {
        _displayNode = [[ASDisplayNode alloc] initWithViewBlock:^UIView * _Nonnull{
            UIView * view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, LSScreenWidth, 30)];
            view.backgroundColor = [UIColor redColor];
            [view addSubview:[self addContentView]];
            if (type == 0) {
                _model1 = model;
                [self setOdd];
            }else if (type == 1){
                _model2 = model;
                [self setAI];
            }else{
                _model3 = model;
                [self setSSD];
                
            }
            return view;
        }];
    }
    [self addSubnode:_displayNode];
    return self;
}


- (UIView *)addContentView{
    UIView * bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, LSScreenWidth-20, 37)];
    bgView.backgroundColor = LSTitleWhiteColor;
    CGFloat width = bgView.frame.size.width/5;
    self.companyName = [[UILabel alloc] init];
    self.companyName.font = LSFontSize12;
    self.companyName.textAlignment = NSTextAlignmentCenter;
    self.companyName.textColor = LSSubColor5D5D5D;
    self.companyName.frame = CGRectMake(0, 0, width, 37);
    
    [bgView addSubview:self.companyName];
    UILabel *instantLable; //即时
    UILabel *firstCount;   //初盘
    for (int i = 0; i < 3; i ++) {
        
        instantLable = [[UILabel alloc] initWithFrame:CGRectMake(width*(i+2), 0, width, 37/2)];
        instantLable.textColor = LSSubColor5D5D5D;
        instantLable.font=LSFontSize12;
        instantLable.textAlignment = NSTextAlignmentCenter;
        [self.instantLableArray addObject:instantLable];
        [bgView addSubview:instantLable];
        
        firstCount = [[UILabel alloc] initWithFrame:CGRectMake(width*(i+2), 37/2, width, 37/2)];
        firstCount.textColor = LSSubColor5D5D5D;
        firstCount.font=LSFontSize12;
        firstCount.textAlignment = NSTextAlignmentCenter;
        [self.firstCountArray addObject:firstCount];
        [bgView addSubview:firstCount];
    }
    
    UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, 36, bgView.frame.size.width, 1)];
    line.backgroundColor = LSLineGrayColor;
    [bgView addSubview:line];
    return bgView;
}

- (ASLayoutSpec *)layoutSpecThatFits:(ASSizeRange)constrainedSize{
    
    ASStackLayoutSpec * stackSpec = [ASStackLayoutSpec horizontalStackLayoutSpec];
    stackSpec.alignItems = ASStackLayoutAlignItemsStretch;
    stackSpec.style.height = ASDimensionMake(37);
//    stackSpec.justifyContent = ASScrollDirectionVerticalDirections
    stackSpec.children = @[_displayNode];
    ASInsetLayoutSpec * inset = [ASInsetLayoutSpec insetLayoutSpecWithInsets:UIEdgeInsetsMake(0, 10, 0, 10) child:stackSpec];
    
    return inset;
    
}


- (void)setOdd{
    
    companyDataList * listModel1 = _model1.companyDataList.firstObject;
    companyDataList * listModel2 = _model1.companyDataList.lastObject;
    self.companyName.text = _model1.CompanyName;
    if (_model1.companyDataList.count == 1) {
        
        NSArray *array1 = @[[NSString stringWithFormat:@"%.2f",listModel2.Odds_Win],[NSString stringWithFormat:@"%.2f",listModel2.Odds_Flat],[NSString stringWithFormat:@"%.2f",listModel2.Odds_Negative]];
        [self.firstCountArray enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            UILabel *lable = (UILabel *)obj;
            lable.text = array1[idx];
        }];
        [self.instantLableArray enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            UILabel *lable = (UILabel *)obj;
            lable.text = array1[idx];
        }];
    }else{
        
        NSArray *array1 = @[[NSString stringWithFormat:@"%.2f",listModel2.Odds_Win],[NSString stringWithFormat:@"%.2f",listModel2.Odds_Flat],[NSString stringWithFormat:@"%.2f",listModel2.Odds_Negative]];
        [self.firstCountArray enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            UILabel *lable = (UILabel *)obj;
            lable.textColor = LSSubColor5D5D5D;
            lable.text = array1[idx];
        }];
        
        //即时
        NSArray *array = @[[NSString stringWithFormat:@"%.2f",listModel1.Odds_Win],[NSString stringWithFormat:@"%.2f",listModel1.Odds_Flat],[NSString stringWithFormat:@"%.2f",listModel1.Odds_Negative]];
        [self.instantLableArray enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            UILabel *lable = (UILabel *)obj;
            lable.text = array[idx];
            lable.textColor = LSSubColor5D5D5D;
        }];
        
        
    }
    
}

- (void)setAI{
    companyDataList * listModel1 = _model2.companyDataList.firstObject;
    companyDataList * listModel2 = _model2.companyDataList.lastObject;
    self.companyName.text = _model2.CompanyName;
    
    NSArray *array = @[listModel1.HD_ZD,listModel1.HD_PK,listModel1.HD_ZD];
    [self.instantLableArray enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        UILabel *lable = (UILabel *)obj;
        lable.text = array[idx];
    }];
    
    NSArray *array1 = @[listModel2.HD_ZD,listModel2.HD_PK,listModel2.HD_ZD];
    [self.firstCountArray enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        UILabel *lable = (UILabel *)obj;
        lable.text = array1[idx];
    }];
    
}
- (void)setSSD{
    companyDataList * listModel1 = _model3.companyDataList.firstObject;
    companyDataList * listModel2 = _model3.companyDataList.lastObject;
    self.companyName.text = _model3.CompanyName;
    NSArray *array = @[listModel1.HD_DQ,listModel1.HD_PK,listModel1.HD_XQ];
    [self.instantLableArray enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        UILabel *lable = (UILabel *)obj;
        lable.text = array[idx];
    }];
    
    NSArray *array1 = @[listModel2.HD_DQ,listModel2.HD_PK,listModel2.HD_XQ];
    [self.firstCountArray enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        UILabel *lable = (UILabel *)obj;
        lable.text = array1[idx];
    }];
}
@end
